package com.adtech.farmProducts.adapter;

import android.view.View;
import android.widget.TextView;

import com.adtech.common.widgets.recycler.RecyclerViewAdapter;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.model.PositionEntity;


/**
 * Author:  xiaocz.
 * Date:    2018/05.04.
 * Descr:  地址搜索
 */
public class SearchListAdapter extends RecyclerViewAdapter<PositionEntity> {

    public SearchListAdapter(AdapterListener<PositionEntity> adapterListener) {
        super(adapterListener);
    }

    @Override
    protected int getItemViewType(int position, PositionEntity data) {
        return R.layout.item_search_address;
    }

    @Override
    protected ViewHolder<PositionEntity> getViewHolder(View view, int viewType) {
        return new InfoTypeViewHolder(view);
    }

    private static class InfoTypeViewHolder extends ViewHolder<PositionEntity> {

        private TextView tvName, tvInfo;

        public InfoTypeViewHolder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.name);
            tvInfo = itemView.findViewById(R.id.city);
        }

        @Override
        protected void onBind(PositionEntity data, int position) {
            tvName.setText(data.getName());
            if("".equals(data.getAddress())){
                tvInfo.setText(data.getCity());
            }else {
                tvInfo.setText(data.getAddress());
            }
        }

        @Override
        public boolean isNeedClick() {
            return true;
        }
    }
}